{include mobile_template('header')}
<link rel="stylesheet" href="{URLROOT}/{$_G[tplurl_mobile]}/css/tuan.css" />
<div class="panel-comm panel-default panel-fullsize">

    <div class="panel-body">
        <ul class="list-group-list">
            <li class="list-group-item">
                <div class="fr">$oid</div>
                订单编号
            </li>
            <li class="list-group-item">
                <div class="fr"><span class="txt-red">&yen;$detail[price]</span></div>
                支付金额
            </li>
            <li class="list-group-item">
                <div class="fr">$status_lng[$detail[status]]</div>
                订单状态
            </li>
            <li class="list-group-item">
                <div class="fr">{date $detail[dateline]}</div>
                生成时间
            </li>
            <li class="list-group-item">
                <div>
                    <div class="fr">{print lang('tuan_mode_'.$tuan[mode])}</div>
                    团购类型
                </div>
                
                <!--{if $tuan['mode'] != 'normal' && $tuan['status']=='succeeded'}-->
                <p class="txt-comm txt-small"><b>{print lang('tuan_mode_'.$tuan[mode])}：</b>下单金额：<span class="txt-red">&yen;</span>$detail[price]，最终价：<span class="txt-red">&yen;</span>$detail[pay_price]，{if $detail[balance_price]>0}差价：<span class="txt-red">&yen;</span>{$detail[balance_price]}，{if $detail[return_balance_time]}系统于 {date $detail[return_balance_time]} 退还差价{else}系统尚未退还差价{/if}{else}没有产生差价{/if}。</p>
                <!--{/if}-->

                <!--{if $tuan[mode] == 'forestall' && $tuan['status']=='new'}-->
                <p class="txt-comm txt-small">
                    {eval $real_price = $ranking-1;}
                    您是第 {$ranking} 位购买用户，预计您的最终单价为：<span class="money">&yen;</span>{print:tuan forestall_price(price/$tuan[price]/prices/$tuan[prices]/peoples_sell/$real_price)}
                </p>
                <!--{/if}-->
            </li>
        </ul>

        <!--{if  $detail[status]=='payed' && ($tuan[sendtype]=='coupon'||$tuan[sendtype]=='coupon_ex')}-->
        <ul class="list-group-list mt10">
            <!--{dbres $list $val}-->
            <li class="list-group-item list-mycolor">
                <div class="fr txt-small">
                    <!--{if $val['status']=='used'}-->
                    <span class="txt-red">已使用<br />{date $val[usetime],'Y-m-d'}</span>
                    <!--{else}-->
                    <span class="txt-primary">有效期<br />{date $val[expiretime],'Y-m-d'}</span>
                    <!--{/if}-->
                </div>
                券号：$val[serial]<br>密码：<span data-name="password" data-value="$val[passward]">点击显示</span>&nbsp;
            </li>
            <!--{/dbres}-->
        </ul>
        <!--{/if}-->

        <div class="list-group-list mt10">
            <div class="list-group-item">
                <div>
                    <div class="fr">
                        <span class="txt-small txt-grey">Tel：$detail[mobile]</span>
                    </div>
                    <span data-name="name">$detail[username]</span>
                </div>
            </div>
            <!--{if $tuan[sendtype]=='express'}-->
            <div class="list-group-item">
                $detail[contact][address]&nbsp;$detail[contact][linkman]
            </div>
            <!--{/if}-->
            {if $detail['express']}
            <a href="http://m.kuaidi100.com/result.jsp?nu=$detail[express][number]" class="list-group-item">
                <div class="fr">
                    No.$detail[express][number]
                    <div class="arrow"></div>
                </div>
                $detail[express][name]【{print lang('tuan_good_status_'.$detail[good_status])}】
            </a>
            {/if}
        </div>

        <div class="list-group-list mt10">
            <a class="list-group-item" href="{url tuan/mobile/do/detail/id/$tuan[tid]}">
                <div class="fr"><span class="arrow"></span></div>
                <div class="richtxt-comm richtxt-img-defaultsize">
                    <div class="fl">
                        <img src="{img $tuan[thumb]}" alt="$tuan[subject]" class="richtxt-img">
                    </div>
                    <div class="richtxt-body">
                        <h4>$tuan[subject]</h4>
                        <p class="txt-comm txt-small txt grey">
                            <span class="txt-red">&yen;{print get_numeric($tuan[price])}</span> × $detail[num]<br>
                        </p>
                    </div>
                </div>
            </a>
        </div>
        <div class="list-group">
            <form method="post" action="{url tuan/mobile/do/pay/rand/$_G[random]}" name="pay_form">
                <input type="hidden" name="oid" value="$detail[oid]">
                <input type="hidden" name="payment_name" id="payment_name" value="">
                <input type="hidden" name="payment" id="payment" value="">
                <!--{if $detail[status]=='new'}-->
                <a class="list-group-item list-mycolor mt10" id="payment_btn" href="#">
                    <input type="hidden" name="payment" value="">
                    <div>
                        <div class="fr">
                            <span id="payment_title">尚未选择</span>
                            <span class="arrow"></span>
                        </div>
                        支付方式
                    </div>
                    <p class="txt-comm txt-small txt-grey" id="payment_des"></p>
                </a>
                <div class="list-group-item" id="enter_password">
                    <div class="fr">
                        <input class="product-order-password" type="password" name="password" value="">
                    </div>
                    请输入帐号支付密码
                </div> 
                <div class="btn-group-vertical full-width btn-group-mt10 mt10" id="submit_box">
                    <button type="submit" class="btn btn-mycolor" value="Yes" name="dosubmit">在线支付</button>
                    <button type="button" class="btn btn-primary" name="cancel_btn">取消订单</button>
                </div>
                <!--{elseif $detail[status]=='payed'}-->  
                <div class="btn-group-vertical full-width  mt10">
                    <!--<button type="button" class="btn btn-primary">申请退款</button>-->
                </div>
                <!--{/if}-->                 
            </form>
        </div>
    </div>

</div>
{if $detail[status]=='new'}
<div class="panel-comm panel-default none" id="payment_box">
    <div class="list-group list-group-insertmod">
        <div class="list-group-heading">余额支付</div>
        <!--{eval $needprice = get_numeric($detail[price]-$user->rmb);}-->
        <a href="#" class="list-group-item" data-name="balance" data-title="余额支付" data-needprice="$needprice">
            <div class="fr"><span class="arrow"></span></div>
            <p class="txt-comm txt-grey">
                账户余额：<span class="txt-red">&yen;<strong>{print get_numeric($user->rmb)}</strong></span>
            </p>
            <!--{if $user->rmb < $detail[price]}-->
            <p class="txt-comm txt-small txt-grey">
                支付金额不足，您先充值 <span class="txt-red">&yen;{$needprice}</span>
            </p>
            <!--{/if}-->
        </a>
        <div class="list-group-heading">在线支付</div>
        <!--{if check_module('pay')}-->
        <!--{if S('pay:alipay_mobile')}-->
        <a href="#" class="list-group-item" data-name="alipay_mobile" data-title="手机支付宝">
            <div class="fr"><span class="arrow"></span></div>
            手机支付宝
        </a>
        <!--{/if}-->
        <!--{if S('pay:wxpay')}-->
        <a href="#" class="list-group-item" data-name="wxpay" data-title="微信支付">
            <div class="fr"><span class="arrow"></span></div>
            微信支付
        </a>
        <!--{/if}-->
        <!--{if $MOD[localpay_des]}-->
        <div class="list-group-heading">线下支付</div>
        <a href="#" class="list-group-item" data-name="offline" data-title="线下支付">
            <div class="fr"><span class="arrow"></span></div>
            <p class="txt-comm txt-small txt-grey">
                {print nl2br(_T($MOD[localpay_des]))}
            </p>
        </a>
        <!--{/if}-->
        <!--{/if}-->
    </div>
</div>
{/if}
<script>
$(document).ready(function() {
    payment();
    $('[data-name="password"]').click(function(event) {
        $(this).text($(this).data('value'));
    });
    $('[name="cancel_btn"]').click(function(event) {
        if(window.confirm('您确定要取消当前订单吗？')) {
            cancelOrder('{url tuan/mobile/do/myorder/op/cancel}', {oid:$oid});
        }
    });
});

//收货地址处理
var payment = function() {

    var lang = {
            offlinepay_des:'{print nl2br(_T($MOD[localpay_des]))}',
            balance_needprice:'对不起，您的账户余额不足，不能使用余额支付，请先充值或选择其他支付方式。'
        }

    var select_addr;

    //初始化
    var init = function() {
        $('#enter_password').hide();
        $('#payment_des').empty().hide();
        //事件绑定
        $('#payment_btn').click(function(event) {
            event.preventDefault();
            select_addr.open();
        });
        //提交支付
        $('form[name="pay_form"]').bind('submit', submit);
        //弹出层初始化
        select_addr = new $.m_drawer('#payment_box', {}, {
            onInit:function(container, workArea) {
                workArea.show();
                workArea.delegate('a.list-group-item', 'click', function(event) {
                    event.preventDefault();
                    if(select_payment($(this))) {
                        container.close();
                    }
                });
            }
        });
    }

    //选择支付方式
    var select_payment = function(my) {
        $('#enter_password').hide();
        $('#submit_box').show();
        $('#payment_des').empty().hide();
        if(my.data('name')=='balance') {
            if(my.data('needprice')>0) {
                alert(lang.balance_needprice);
                return;
            }
            $('#enter_password').show();
        } else if(my.data('name')=='offline') {
            $('#payment_des').text(lang.offlinepay_des).show();
            $('#submit_box').hide();
        }
        $('#payment_title').text(my.data('title'));
        $('input[name="payment"]').val(my.data('name'));
        return true;
    }

    var submit = function(e) {
        var form = $('form[name="pay_form"]');
        var payment = form.find('input[name="payment"]').val();
        if(!payment) {
            alert('您未选择支付方式。');
            return false;
        } else if(payment=='cod' || payment=='balance') {
            if(form.find('input[name="password"]').val()=='') {
                alert('您未填写支付密码。');
                return false;                
            }
            if(!window.confirm('您确定要支付订单吗？')) return false;
        }
        //return true;
        //
        form[0].submit();
        return;
    }

    init();
}

var cancelOrder = function(post_url, params) {
    var frm = $('<form method="post" action="'+post_url+'">');
    $.each(params, function(name, key) {
         frm.append('<input type="hidden" name="'+name+'" value="'+key+'">');
    });
    frm.append('<input type="hidden" name="dosubmit" value="Yes">');
    frm[0].submit();
}

</script>
{include mobile_template('footer')}